﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace WmsApp.UI
{
    public interface INumericScopeQuerier
    {
        /// <summary>
        /// 启用框的文本内容
        /// </summary>
        string CheckEditOnText { get; set; }
        string GetQueryCondition();
        string Field { get; set; }
    }

    public partial class NumericScopeQuerier : DevExpress.XtraEditors.XtraUserControl, INumericScopeQuerier
    {
        public NumericScopeQuerier()
        {
            InitializeComponent();
        }

        private void CheckEditOnCheckedChanged(object sender, EventArgs e)
        {
            if(this.checkEditOn.Checked)
            {
                this.labelControl2.Enabled = true;
                this.labelControl1.Enabled = true;
                this.textEdit1.Enabled = true;
                this.textEdit2.Enabled = true;
            }
            else
            {
                this.labelControl2.Enabled = false;
                this.labelControl1.Enabled = false;
                this.textEdit1.Enabled = false;
                this.textEdit2.Enabled = false;
            }
        }

        #region INumericScopeQuerier Members

        public string CheckEditOnText
        {
            get
            {
                return this.checkEditOn.Properties.Caption;
            }
            set
            {
                this.checkEditOn.Properties.Caption = value;
            }
        }

        public string GetQueryCondition()
        {
            if(String.IsNullOrEmpty(Field))
            {
                Exceptions.ExceptionHandler.ShowException("Field属性必须赋值！NumericScopeQuerier！");
            }
            string condition = "";
            if (!checkEditOn.Checked)
            {
                return condition;
            }
            condition = " and {0} >= {1} and {0} <={2}";
            condition = string.Format(condition, Field, this.textEdit1.EditValue, this.textEdit2.EditValue);
            return condition;
        }
        
        /// <summary>
        /// 字段属性
        /// </summary>
        public string Field { get; set; }

        #endregion


    }
}
